﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.Util;
using System.IO;

namespace HttpUploader5.demoAccess.db
{
	/// <summary>
	/// 配置文件
	/// </summary>
	public class HttpUploaderCfg
	{
		string m_UploadPath;	//上传路径。d:\www\upload\201204\09
		string m_UploadFolder;	//上传文件夹。d:\www\upload\
		string m_RelatPath;		//相对路径。/upload/201204/09
		string m_Domain;		//网站域名。
		string m_CurFile;		//
		
		/// <summary>
		/// 构造函数
		/// </summary>
		public HttpUploaderCfg()
		{
			//F:\www\upload\
			this.m_UploadFolder = HttpContext.Current.Server.MapPath("/upload/");
		}

		/// <summary>
		/// 创建上传路径
		/// d:\www\upload\2012\04\10
		/// </summary>
		public void CreateUploadPath()
		{
			DateTime timeCur = DateTime.Now;
			string timeStr = timeCur.ToString("yyyy")+"\\"+timeCur.ToString("MM")+"\\"+timeCur.ToString("dd");
			this.m_RelatPath = timeCur.ToString("yyyy") + "/" + timeCur.ToString("MM") + "/" + timeCur.ToString("dd");
			this.m_UploadPath = Path.Combine(this.m_UploadFolder, timeStr);
			//
			if (!Directory.Exists(this.m_UploadPath))
			{
				Directory.CreateDirectory(this.m_UploadPath);
			}
		}

		//创建用户文件夹
		public void CreateUploadPath(string uid)
		{
			this.m_RelatPath = "upload/"+uid;
			this.m_UploadPath = Path.Combine(this.m_UploadFolder, uid);
		}

		/// <summary>
		/// 获取上传路径
		/// </summary>
		/// <returns>d:\www\upload\201204\10</returns>
		public string GetUploadPath()
		{
			return this.m_UploadPath;
		}

		/// <summary>
		/// 获取相对路径
		/// </summary>
		/// <returns>/upload/201204/10</returns>
		public string GetRelatPath()
		{
			return this.m_RelatPath;
		}
	}
}
